using System;
using System.Collections.Generic;
using AllIsWell.Core.Models;
using AllIsWell.Tests.TestData;
using NUnit.Framework;

namespace AllIsWell.Services.Tests.PageServiceTests
{
    [TestFixture]
    class GetFreshPage : PageServiceTest
    {
        private int _destinyId;
        private Destiny _expectedDestiny;

        [SetUp]
        public void SetUp()
        {
            _destinyId = 1;
            _expectedDestiny = DestinySeed.GetDestiny(_destinyId);
            DestinyRepositoryMock.Setup(repo => repo.GetDestiny(_destinyId))
                                 .Returns(_expectedDestiny);
        }

        [Test]
        public void ShouldReturnPageWithDestinyForGivenId()
        {
            var page = PageService.GetFreshPage(_destinyId);

            Assert.AreEqual(_expectedDestiny, page.Destiny);
        }

        [Test]
        public void ShouldReturnPageWithRetrospectsForEachWhatsInGivenDestiny()
        {
            var expectedWhats = _expectedDestiny.Whats;

            var page = PageService.GetFreshPage(_destinyId);

            Assert.AreEqual(expectedWhats.Count, page.Retrospects.Count);
            Assert.AreEqual(expectedWhats[0], page.Retrospects[0].What);
            Assert.AreEqual(expectedWhats[1], page.Retrospects[1].What);
        }

        [Test]
        public void ShouldReturnPageWithDateTimeAsToday()
        {
            var page = PageService.GetFreshPage(1);

            Assert.AreEqual(DateTime.Today, page.DateTime);
        }

        [Test]
        public void ShouldIgnoreRetrospectsHavingDisabledWhat()
        {
            var disabledWhat = WhatSeed.GetDisabledWhat();
            _expectedDestiny.Whats = new List<What>(new[] { disabledWhat });

            var page = PageService.GetFreshPage(_destinyId);

            Assert.AreEqual(0, page.Retrospects.Count);
        }
    }
}